#include "expenserecordlist.h"

ExpenseRecordList::ExpenseRecordList(){}

int ExpenseRecordList::categorysize(){
    return expenseCategoryList.size();
}

QString ExpenseRecordList::getcategory(int i){
    return expenseCategoryList[i];
}

void ExpenseRecordList::operator=(ExpenseRecordList copy){
    RCL = copy.getRecordList();
    expenseCategoryList = copy.getCategoryList();
}

void ExpenseRecordList::addCategory(QString category){
    int i = 0;
    bool exists = false;
    // Check if the category exists before adding
    for(i = 0; i < this->expenseCategoryList.size(); i++){
        if(this->expenseCategoryList[i] == category){
            exists = true;
            break;
        }
    }
    if(!exists)
        this->expenseCategoryList.push_back(category);
}

void ExpenseRecordList::removeCategory(QString category){
    int i = 0;
    // Do not need to check if category exists before removing.
    for(i = 0; i < expenseCategoryList.size(); i++){
        if(this->expenseCategoryList[i] == category){
            this->expenseCategoryList.erase((this->expenseCategoryList.begin() + i));
            break;
        }
    }
}

double ExpenseRecordList::calculateExpense(){
    int i = 0;
    double expense = 0;
    for(i = 0; i < this->RCL.size(); i ++)
        expense += RCL[i].getamount();
    return expense;
}

vector<QString> ExpenseRecordList::getCategoryList(){
    return this->expenseCategoryList;
}

void ExpenseRecordList::clearCategoryList(){
    this->expenseCategoryList.clear();
}

vector<QString> ExpenseRecordList::expenseCategoryList;
